{% extends "base.html" %}
{% block title %}Rules{% endblock %}
{% block content %}
    <div class="row">
        <div class="small-6 large-centered columns">
            <h2>Rules Management</h2>
        </div>
    </div>
    <div class="row">
        <div class="small-8 large-centered columns">
            <div class="row">
                <div class="small-4 columns">
                    <h4>Search Filters</h4>
                </div>
            </div>
            <form id="rule-filter" action="" method="get">
                <div class="row">
                    <div class="small-4 columns">
                        <label>Signature Search String</label>
                    </div>
                </div>
                <div class="row">
                    <div class="small-4 columns">
                        <input type="text" name="sig_name" value="{{ sig_name }}" placeholder="Signature Name" />
                    </div>
                    <div class="small-2 columns">
                        <input class="tiny button" type="submit" value="GO" />
                    </div>
                </div>
            </form>
        </div>
    </div>
    <div style="max-width: 90.5rem;" class="row">
        <div class="small-12 columns">
            <input id="_csrf_token" name="_csrf_token" type="hidden" value="{{ csrf_token() }}">
            <table id="rule-table">
                <thead>
                    <tr>
                        <th></th>
                        <th width="170">Date</th>
                        <th>SID</th>
                        <th>Rev</th>
                        <th>Revs</th>
                        <th width="290">Message</th>
                        <th width="150">Class Type</th>
                        <th>References</th>
                        <th width="290">Notes</th>
                        <th>Active</th>
                    </tr>
                </thead>
                <tbody>
                    {% for ru in rules.items %}
                    <tr>
                        <td>{{ loop.index }}</td>
                        <td>{{ ru.Rule.date|fdate }}</td>
                        <td>{{ ru.Rule.sid }}</td>
                        <td>{{ ru.Rule.rev }}</td>
                        <td>{{ ru.nrevs }}</td>
                        <td>{{ ru.Rule.message }}</td>
                        <td>{{ ru.Rule.classtype }}</td>
                        <td>
                            <select>
                        {% for ref in ru.Rule.references %}
                                <option disabled>"{{ ref.text }}"</option>
                        {% endfor %}
                            </select>
                        </td>
                        <td>
                            <textarea data-rule-id="{{ ru.Rule.id }}" data-field-name="notes" class="text-edit">{{ ru.Rule.notes if ru.Rule.notes != None }}</textarea>
                        </td>
                        <td>
                            <input class="checkbox" data-rule-id="{{ ru.Rule.id }}" type="checkbox" {% if ru.Rule.is_active %}checked{% endif %}/>
                        </td>
                    </tr>
                    {% endfor %}
                </tbody>
            </table>
            {% from "pagination.html" import render_pagination %}
            {{ render_pagination(rules, view, request.args.to_dict()) }}
        </div>
    </div>
{% endblock %}
